package cn.com.bluemoon.bd.flink.dim.processor;

import com.google.common.collect.Lists;


import java.util.List;

/**
 * 维表处理组合类
 * @param <I> 输入数据的类型
 * @param <W> 宽表数据的类型
 * @author 王仁线
 */
public class DimProcessorList<I, W> extends AbstractDimProcessor<I, W> {
    private List<IDimProcessor> processors = Lists.newArrayList();

    public void open() throws Exception {
        for (IDimProcessor processor : this.processors) {
            processor.open();
        }
    }

    @Override
    public void process(I in, W w) throws Exception {
        for (IDimProcessor processor : this.processors) {
            processor.process(in, w);
        }
    }

    @Override
    public void reload() throws Exception {
        for (IDimProcessor processor : this.processors) {
            try {
                processor.reload();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    public void addProcessor(IDimProcessor processor) {
        this.processors.add(processor);
    }

    public void close() throws Exception {
        for (IDimProcessor processor : this.processors) {
            try {
                processor.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}
